package com.cg.controller;

import com.cg.dto.Result;
import com.cg.dto.ResultUtils;
import com.cg.entity.Area;
import com.cg.service.AreaService;
import com.cg.vo.AreaListVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Area)表控制层
 *
 * @author chengong
 * @since 2024-01-03 17:26:41
 */
@RestController
@RequestMapping("/area")
public class AreaController {
    /**
     * 服务对象
     */
    @Resource
    private AreaService areaService;

    /**
     * 查询省
     */
    @GetMapping("/queryProvince")
    public Result<List<Area>> queryShen(){
        return ResultUtils.returnDataSuccess(areaService.queryShen());
    }


    /**
     * 查询市
     */
    @GetMapping("/queryCity")
    public Result<List<Area>> queryShi(@RequestParam("areaId") Integer areaId){
        return ResultUtils.returnDataSuccess(areaService.queryShi(areaId));
    }

    /**
     * 查询区
     */
    @GetMapping("/queryArea")
    public Result<List<Area>> queryQu(@RequestParam("areaId") Integer areaId){
        return ResultUtils.returnDataSuccess(areaService.queryQu(areaId));
    }

    /**
     * 省市区级联，查询省市区
     */
    @GetMapping("/getAreas")
    public Result<List<AreaListVo>> getAreas(){
        List<AreaListVo> areaList = areaService.getAreas();
        return ResultUtils.returnDataSuccess(areaList);
    }
}

